/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 string_insensitive_compare.h

	$Header: /heroes4/string_insensitive_compare.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( STRING_INSENSITIVE_COMPARE_H_INCLUDED )
#define STRING_INSENSITIVE_COMPARE_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <cstring>
#include <functional>
#include <string>

// -------------------------------------------------------------------------------
// string_insensitive_compare() function - does a case insensitive compare of
// two std::string's.
// -------------------------------------------------------------------------------

int string_insensitive_compare( std::string const & left, std::string const & right );

// -------------------------------------------------------------------------------
// string_insensitive_compare() function - does a case insensitive compare of
// a std::string with a c-style string.
// -------------------------------------------------------------------------------

int string_insensitive_compare( std::string const & left, char const * right );

inline int string_insensitive_compare( char const * left, std::string const & right )
{
	return -string_insensitive_compare( right, left );
}

// -------------------------------------------------------------------------------
// string_insensitive_compare() function - does a case insensitive compare of
// two c-style strings.
// -------------------------------------------------------------------------------

inline int string_insensitive_compare( char const * left, char const * right )
{
	return _stricmp( left, right );
}

// -------------------------------------------------------------------------------
// t_string_insensitive_less struct - a function object class for doing case
// insensitive compares of std::string's.  Suitable for use as an STL predicate.
// -------------------------------------------------------------------------------

struct t_string_insensitive_less : public std::binary_function< std::string, std::string, bool >
{
	bool operator()( std::string const & left, std::string const & right ) const;
};

inline bool t_string_insensitive_less::operator()( std::string const & left, std::string const & right ) const
{
	return string_insensitive_compare( left, right ) < 0;
}

#endif // !defined( STRING_INSENSITIVE_COMPARE_H_INCLUDED )
